package com.mj.specialnetname.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.mj.specialnetname.util.HttpUtils;
import com.mj.specialnetname.util.RegUtil;

/**
 * 个性网名
 * @author zhaominglei
 * @date 2015-12-5
 * 
 */
public class SpecialnetnameService extends BaseService {
	@SuppressWarnings("unused")
	private static final String TAG = SpecialnetnameService.class.getSimpleName();
	
	@SuppressWarnings("serial")
	public Map<String, String> ncharMap = new LinkedHashMap<String, String>() {
		{
			put("纯朴", "0");
			put("普通", "2");
			put("尚可辨认", "3");
			put("难以辨认的", "4");
			put("极其愚蠢的", "5");
		}
	};
	
	public List<String> getSpecialnetnameInfo(String key, String nchar) {
		if (key == null || key.equals("") || nchar == null || nchar.equals("")) {
			return null;
		}
		String url = "http://www.388g.com/huoxing/?key="+HttpUtils.encodeURI(key, "utf-8")+"&B1=%E9%A9%AC%E4%B8%8A%E7%94%9F%E6%88%90&nchar="+ncharMap.get(nchar);
		String html = HttpUtils.doGetFor388g(url, null);
		if (html != null && !html.equals("")) {
			String result = RegUtil.getMatchRegStr(html, "<table(.+?)</table>");
			result = "<table " + result + "</table>";
			result = result.replaceAll("<script src=\"/js/160x600.js\" language=\"JavaScript\"></script>", "");
			
			List<String> list = new ArrayList<String>();
			list.add("<strong><font color=\"#ff3300\">文字纯转换</font></strong>");
			List<String> listother = RegUtil.getMatchRegStrs(result, "<td align=\"center\">(.+?)</td>");
			list.addAll(listother);
			return list;
		}
		return null;
	}
}
